<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Role List</title>
<link rel="stylesheet" type="text/css" href="../../themes/general.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<script type="text/javascript" src="../../scripts/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../scripts/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../scripts/src/jquery.parser.js"></script>
<script type="text/javascript" src="../../scripts/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../scripts/sessionExpriation.js"></script>
<script type="text/javascript">
		$(function(){
			$('#query_result').datagrid({
				onDblClickRow : function(rowIndex, rowData) {
					viewRole(rowData["id"]);
				}
			});
		
			var pg = $("#query_result").datagrid("getPager");
			if (pg) {
				$(pg).pagination({		
					onBeforeRefresh : function() {
					},
					onRefresh : function(pageNumber, pageSize) {
						do_submit(pageNumber, pageSize)
					},
					onChangePageSize : function() {
					},
					onSelectPage : function(pageNumber, pageSize) {
						do_submit(pageNumber, pageSize);
					}
				});
			}
			
			$('#btn_query').bind('click', function(){  
				$(pg).pagination('select', 1);
        	});
			
			$('#btn_reset').bind('click', function(){  
				$('#query_search_Div').form('clear');
        	});
			
			init_view_by_permission();
		});
	
	function do_submit(pageNumber, pageSize) {
		$('#query_form').form('submit', {
			url : '../../role/query.ajax',
			cache: false,
			onSubmit:function(param){
				param.paging = true;
				param.limit = pageSize;
				param.offset = (pageNumber-1)*pageSize;
				return $(this).form('validate');
			},
			success : function(data) {
				var obj = $.parseJSON(data);
				$('#query_result').datagrid('loadData', obj)
			}
		});
	}
	
		
	function do_view() {
		var row = $('#query_result').datagrid('getSelected');
		if(row == null){
			$.messager.alert('Info', '请选择行', 'info');
			return;
		}
		viewRole(row.id);
	}
	
	function viewRole(id) {
		parent.addTabWithIcon("角色信息", "./role/view.htm?roleId="+id, "icon-role");
	}
	
	function do_edit() {
		var row = $('#query_result').datagrid('getSelected');
		if(row == null){
			$.messager.alert('Info', '请选择行', 'info');
			return;
		}
		parent.addTabWithIcon("修改角色信息", "./role/edit.htm?roleId="+row.id, "icon-eidt");
	}
	
	function init_view_by_permission() {
		$.ajax({
			url : '../../ana/checkPermission.ajax',
			type : 'get',
			dataType : 'JSON',
			data : {
				permissionCode : 'ROLE_EDIT'
			},
			success : function(data) {
				if (data.success) {
					$('#divBtnEdit').show();
				} else {
					$('#divBtnEdit').hide();
				}
			}
		});
		$.ajax({
			url : '../../ana/checkPermission.ajax',
			type : 'get',
			dataType : 'JSON',
			data : {
				permissionCode : 'ROLE_VIEW'
			},
			success : function(data) {
				if (data.success) {
					$('#divBtnView').show();
				} else {
					$('#divBtnView').hide();
				}
			}
		});
		
	}
	
	</script>
</head>
<body>

	<form id="query_form" method="post">
		<div style="margin: 5px 0"></div>
		<div style="margin: 0 5px" id='query_search_Div'>
			<table class="table_view" style="font-size: 12px; background: #F1F1F1;width:99.5%;">
				<tr>
					<td class="td_view_name">角色编号</td>
					<td class="td_view_value">
						<input class="input_120" type="text" name="roleId" id="roleId">
					</td>
					<td class="td_view_name">角色名称</td>
					<td class="td_view_value" colspan="3">
						<input class="input_120" type="text" name="roleName" id="roleName">
					</td>
				</tr>
				<tr>
					<td colspan="4" align="center" class="td_view_name">
						<div align="center">
							<a id="btn_query" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search">查询</a> 
							<a id="btn_reset" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-reset">重置</a>
						</div>
					</td>
				</tr>
			</table>
		</div>
		<div style="margin: 10px 0;"></div>
		<div style="margin: 0 5px">
			<table class="easyui-datagrid" title="查询结果" id="query_result"
				data-options="singleSelect:true,pagination:true,rownumbers:true"
				toolbar="#tb">
				<thead>
					<tr>
						<th field="ck" checkbox="true"></th>
						<th data-options="field:'id',width:60">角色编号</th>
						<th data-options="field:'name',width:80">角色名称</th>
						<th data-options="field:'statusName',width:80">状态</th>
						<th data-options="field:'desc',width:250">描述</th>
						<th data-options="field:'createDatetime',width:160">创建时间</th>
						<th data-options="field:'updateDatetime',width:160">更新时间</th>
					</tr>
				</thead>
			</table>

			<div id="tb">
				<div id="divBtnView" style="float:left">
					<a href="#" class="easyui-linkbutton" iconCls="icon-view" plain="true" onclick="javascript:do_view()">查看</a>
				</div>
				<div id="divBtnEdit" style="float:left">
					<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:do_edit()">修改</a>
				</div>	
			</div>
		</div>
	</form>
	
</table>
</div>
</div>
</body>